<?php
/**
 * @version		$Id: view.html.php 34 2009-08-17 14:47:55Z naveen.gavini $
 * @package		Joomla
 * @subpackage	Joomla Multisite
 * @copyright	Copyright (C) 2009 Open Source Matters. All rights reserved.
 * @license		GNU/GPL, see LICENSE.php
 * Joomla! is free software. This version may have been modified pursuant to the
 * GNU General Public License, and as distributed it includes or is derivative
 * of works licensed under the GNU General Public License or other free or open
 * source software licenses. See COPYRIGHT.php for copyright notices and
 * details.
 */

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view' );

/**
 * Multisite View
 *
 * @package    Multisite
 * @subpackage Components
 */
class MultisitesViewMultisite extends JView
{
	/**
	 * display method of Multisite view
	 * @return void
	 **/
	function display($tpl = null)
	{
		// If this is help page ignore rest
		if ($this->getLayout()=='help'){
			JToolBarHelper::title(   JText::_( 'Multisite' ).': <small><small>[ Help ]</small></small>' );
			parent::display($tpl);
		}else{
			// Get the multisite
			$multisite		=& $this->get('Data');
			$tables			=& $this->get('Tables');
			$views			=& $this->get('Views');

			$db =& JFactory::getDBO();
			$query='SELECT id, prefix, name FROM #__multisite';
			$db->setQuery($query);
			$sites=$db->loadObjectList();

			// Get views and their definitions
			$query='SELECT TABLE_NAME, VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS';
			$db->setQuery($query);
			$viewdefs=$db->loadObjectList();

			$isNew		= ($multisite->id < 1);

			$text = $isNew ? JText::_( 'New' ) : JText::_( 'Edit' );
			JToolBarHelper::title(   JText::_( 'Multisite' ).': <small><small>[ ' . $text.' ]</small></small>' );
			if ($this->getLayout()=='edit'){
				JToolBarHelper::save('saveEdit');
			}
			else if ($this->getLayout()=='sync'){
				JToolBarHelper::save('saveSync');
			}
			else{
				JToolBarHelper::save();
			}

			if ($isNew)  {
				JToolBarHelper::cancel();
			} else {
				// for existing items the button is renamed `close`
				JToolBarHelper::cancel( 'cancel', 'Close' );
			}

			$this->assignRef('multisite',		$multisite);
			$this->assignRef('tables',			$tables);
			$this->assignRef('views',			$views);
			$this->assignRef('viewdefs',		$viewdefs);
			$this->assignRef('sites',			$sites);

			parent::display($tpl);
		}
	}
}